package com.lyt.springboot.util.algorithm;



public class S9 {
    public static void main(String[] args) {
        S9 s9 = new S9();
        String s0 = s9.trans("This is a sample");
        System.out.println(s0);
        String a = "This is a sample";
        StringBuilder builder = new StringBuilder(a);
        String s = builder.reverse().toString();
        System.out.println(s);
    }




    public String trans(String s) {

        String[] strArray = s.split(" ",-1);
        StringBuilder strbuild = new StringBuilder();
        for (int i = strArray.length - 1; i >= 0; i--) {
            strbuild.append(reverse(strArray[i])); //数组转换为字符串
            //最后一个字符串后面不再附加空格
            if(i==0) {
                break;
            }
            //字符串之间附加空格
            strbuild.append(" ");
        }
        return strbuild.toString();
    }

    //大小写转换
    private String reverse(String s){
        StringBuilder res= new StringBuilder();
        for(char ch:s.toCharArray()){
            if(Character.isLowerCase(ch)){
                res.append(Character.toUpperCase(ch));
                continue;
            }
            if(Character.isUpperCase(ch)){
                res.append(Character.toLowerCase(ch));
                continue;
            }
        }
        return res.toString();
    }

    public String trans1(String s) {
        StringBuilder builder = new StringBuilder(s);
        String s1 = builder.reverse().toString();
        return "";

    }

}
